package com.xuecheng.teaching.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.commons.model.dto.*;
import com.xuecheng.commons.model.vo.CourseWorkRecVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.teaching.domain.CourseWorkRec;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.teaching.service.CourseWorkRecService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class CourseWorkRecController {

    @Autowired
    private CourseWorkRecService  courseWorkRecService;

    //  作业提交记录[按照课程分组]
    @PostMapping("/work-record/list")
    public ResponseResult workRecord(PageRequest request, @RequestBody WorkCommitDto workCommitDto){
        return courseWorkRecService.workRecord(request,workCommitDto);
    }


    //根据课程id查询
    @GetMapping("/findMsgByCourseId")
    public ResponseResult findMsgByCourseId(Long courPubId){
        //调用service
        LambdaQueryWrapper<CourseWorkRec> qw = new LambdaQueryWrapper<>();
        qw.eq(CourseWorkRec::getCoursePubId,courPubId);
        CourseWorkRec workRec = courseWorkRecService.getOne(qw);
        //转vo
        CourseWorkRecVo vo = BeanHelper.copyProperties(workRec, CourseWorkRecVo.class);
        return ResponseResult.okResult(vo);
    }

    //  批改作业
    @PutMapping("/work-record/correction")
    public ResponseResult correction(@RequestBody WorkRecordDto dto){
        return courseWorkRecService.correction(dto);
    }
}
